/*
 * Reactor.cpp
 *
 *  Created on: 9 Sep 2011
 *      Author: Allan
 */

#include "Reactor.h"

Reactor::Reactor(System& system) :
system(system), dtMin(1.0E-6), dtMax(unsigned(-1)), dt(1.0E-6)
{
	kineticSolver.Initialiaze(system.GetMultiphase(), system.GetEquilibriumReactions(), system.GetKineticReactions());
	kineticSolver.SetControlSolution(0, 1.0E-6);
}

void Reactor::SetMinimumTimeStep(double dtMin)
{
	this->dtMin = dtMin;
}

void Reactor::SetMaximumTimeStep(double dtMax)
{
	this->dtMax = dtMax;
}

void Reactor::SetAdaptiveTimeStepControl(double epsAbs, double epsRel)
{
	kineticSolver.SetControlSolution(epsAbs, epsRel);
}

double Reactor::GetTimeStep() const
{
	return dt;
}

void Reactor::React(double& t, double tEnd)
{
	  double T = system.GetTemperature();
	  double P = system.GetPressure();
	VectorXd n = system.GetComposition();
	
	kineticSolver.Iterate(t, tEnd, dt, T, P, n);
	
	system.SetComposition(n);
}
